<?php
/**
 * @version        $Id: admin_sysmain.php 2014年8月20日Z yeshili $
 * @package        YeshiliCMS.Admin
 * @copyright      Copyright (c) 2014 - 2050, YeshiliCMS, Inc.
 * @license        http://help.****.com/YeshiliCMS/help.html
 * @link           http://www.****.com
 */
include_once '../inc/config.php';
include_once 'admin_session.php';
get_rank($_SESSION['id']);
$act = getvar('act');
if ($act=='update'){
	get_record('系统配置','mod');
	$file_name = '../inc/config.php'; //要替换操作的文件
	$fp = fopen($file_name,'r'); //打开要替换的文件
	$cfg_sitename = htmlspecialchars(stripcslashes($_POST['cfg_sitename']),ENT_QUOTES);
	$cfg_httpurl = htmlspecialchars(stripcslashes($_POST['cfg_httpurl']),ENT_QUOTES);
	$cfg_templatesdir = htmlspecialchars(stripcslashes($_POST['cfg_templatesdir']),ENT_QUOTES);
	$cfg_record = htmlspecialchars(stripcslashes($_POST['cfg_record']),ENT_QUOTES);
	$cfg_sendmail_bysmtp = htmlspecialchars(stripcslashes($_POST['cfg_sendmail_bysmtp']),ENT_QUOTES);
	$cfg_smtp_server = htmlspecialchars(stripcslashes($_POST['cfg_smtp_server']),ENT_QUOTES);
	$cfg_smtp_port = htmlspecialchars(stripcslashes($_POST['cfg_smtp_port']),ENT_QUOTES);
	$cfg_smtp_email = htmlspecialchars(stripcslashes($_POST['cfg_smtp_email']),ENT_QUOTES);
	$cfg_smtp_user = htmlspecialchars(stripcslashes($_POST['cfg_smtp_user']),ENT_QUOTES);
	$cfg_smtp_pass = htmlspecialchars(stripcslashes($_POST['cfg_smtp_pass']),ENT_QUOTES);
	if(!$fp){
		echo $file_name."文件不存在！";
	}
	@$conf_file = fread($fp,filesize($file_name));
	$conf_file = preg_replace("/cfg_sitename\s*\=\s(\'|\")(.*?)(\"|')/","cfg_sitename = \"" . $cfg_sitename. "\"",$conf_file); 
	$conf_file = preg_replace("/cfg_httpurl\s*\=\s(\'|\")(.*?)(\"|')/","cfg_httpurl = \"" . $cfg_httpurl. "\"",$conf_file); 
	$conf_file = preg_replace("/cfg_templatesdir\s*\=\s(\'|\")(.*?)(\"|')/","cfg_templatesdir = \"" . $cfg_templatesdir. "\"",$conf_file);
	$conf_file = preg_replace("/cfg_record\s*\=\s(\'|\")(.*?)(\"|')/","cfg_record = \"" . $cfg_record. "\"",$conf_file); 
	$conf_file = preg_replace("/cfg_sendmail_bysmtp\s*\=\s(\'|\")(.*?)(\"|')/","cfg_sendmail_bysmtp = \"" . $cfg_sendmail_bysmtp. "\"",$conf_file); 
	$conf_file = preg_replace("/cfg_smtp_server\s*\=\s(\'|\")(.*?)(\"|')/","cfg_smtp_server = \"" . $cfg_smtp_server. "\"",$conf_file); 
	$conf_file = preg_replace("/cfg_smtp_port\s*\=\s(\'|\")(.*?)(\"|')/","cfg_smtp_port = \"" . $cfg_smtp_port. "\"",$conf_file); 
	$conf_file = preg_replace("/cfg_smtp_email\s*\=\s(\'|\")(.*?)(\"|')/","cfg_smtp_email = \"" . $cfg_smtp_email. "\"",$conf_file); 
	$conf_file = preg_replace("/cfg_smtp_user\s*\=\s(\'|\")(.*?)(\"|')/","cfg_smtp_user = \"" . $cfg_smtp_user. "\"",$conf_file); 
	$conf_file = preg_replace("/cfg_smtp_pass\s*\=\s(\'|\")(.*?)(\"|')/","cfg_smtp_pass = \"" . $cfg_smtp_pass. "\"",$conf_file); 
	if(!@$fp = fopen($file_name,'w')) 
	echo "没有写入".$file_name."的权限";
	$fw = fwrite($fp, trim($conf_file));
	fclose($fp);	
	echo "<script>alert('操作成功!');window.location='admin_sysmain.php';</script>";
}
include YESHILITEMPLETS."/admin_sysmain.htm";
?>
